﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Neo4jClient;

namespace WinFormsApp1
{
    public class CommonEntity: ICommonEntity
    {
        public string id { get; set; }
        public string name { get; set; }
        public List<string> labels { get; set; }=new List<string>();
        public Dictionary<string, string> properties { get; set; }

        internal string GetName()
        {
            return properties["name"];
        }

        internal void SetGroup(string v)
        {
            if (properties.ContainsKey("group"))
            {
                properties["group"] = v;
            }
            else
            {
                properties.Add("group", v);
            }
        }
        internal string GetGroup()
        {
            if (properties.ContainsKey("group"))
            {
                return properties["group"];
            }
            else
            {
                return null;
            }
        }

        internal string GetValue(string key)
        {
            if (properties.ContainsKey("key"))
            {
                return properties["key"];
            }
            else
            {
                return null;
            }
        }

        internal SimpleTaskEntity ToSimpleTaskEntity()
        {
            var r= new SimpleTaskEntity();
            r.id = id;
            r.name=this.GetName();
            r.group=this.GetGroup();
            r.planStartTime = this.GetValue("planStartTime");
            r.planEndTime = this.GetValue("planEndTime");
            r.realStartTime = this.GetValue("realStartTime");
            r.realEndTime = this.GetValue("realEndTime");
            r.worker= this.GetValue("worker");
            r.challenge = this.GetValue("challenge");
            return r;
        }

        internal void Check()
        {
            if (properties == null) { properties = new Dictionary<string, string>(); }
            if (properties.ContainsKey("name") == false)
            {
                properties.Add("name", name);
            }
        }
    }

    
}
